﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.master" AutoEventWireup="true" CodeBehind="MaterialStockOut.aspx.cs" Inherits="UdrinkWater_Project.Admin.MaterialStockOut" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <dx:ASPxRoundPanel ID="ASPxRoundPanel1" runat="server" 
        HeaderText="เบิกวัสดุ อุปกรณ์" Width="100%">
        <PanelCollection>
            <dx:PanelContent ID="PanelContent1" runat="server" SupportsDisabledAttribute="True">
                <table style="width:100%;">
                    <tr>
                        <td>
                            <asp:Panel ID="Panel2" runat="server">
                            <fieldset>
                            <legend>วันที่เวลา</legend>
                                <table style="width:100%;">
                                    <tr>
                                        <td style="height: 26px; width: 351px;" width="100%">
                                        <asp:UpdatePanel ID="updDateOrder" runat="server">
                                            <ContentTemplate>
                                                <table style="width: 349%">
                                                    <tr>
                                                        <td style="width: 109px; height: 35px;">
                                                            <dx:ASPxLabel ID="ASPxLabel3" runat="server" Text="วันที่และเวลา:">
                                                            </dx:ASPxLabel>
                                                        </td>
                                                        <td style="height: 35px; width: 245px" width="100%">
                                                            <dx:ASPxTextBox ID="txtOrderDate" runat="server" BackColor="#D3E4A6" ReadOnly="True"
                                                                Width="225px">
                                                            </dx:ASPxTextBox>
                                                        </td>
                                                        <td rowspan="5">
                                                         <asp:Panel ID="Panel1" runat="server" Width="600px">
                                                            <fieldset>
                                                                <legend>วัตถุดิบคงเหลือ</legend>
                                                                <dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" 
                                                                    DataSourceID="sqlStock" KeyFieldName="Material_ID" Width="100%">
                                                                    <Columns>
                                                                        <dx:GridViewDataTextColumn Caption="รหัสวัตถุดิบ" FieldName="Material_ID" 
                                                                            ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="1">
                                                                        </dx:GridViewDataTextColumn>
                                                                        <dx:GridViewDataTextColumn Caption="ชื่อวัตถุดิบ" FieldName="Materail_name" 
                                                                            ShowInCustomizationForm="True" VisibleIndex="2">
                                                                        </dx:GridViewDataTextColumn>
                                                                        <dx:GridViewDataTextColumn Caption="จำนวนคงเหลือ" FieldName="TotalSum" 
                                                                            ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="3">
                                                                        </dx:GridViewDataTextColumn>
                                                                        <dx:GridViewDataTextColumn Caption="หน่วยนับ" FieldName="Unit_Name" 
                                                                            ShowInCustomizationForm="True" VisibleIndex="4">
                                                                        </dx:GridViewDataTextColumn>
                                                                    </Columns>
                                                                    <Settings ShowFilterRow="True" />
                                                                </dx:ASPxGridView>
                                                            </fieldset></asp:Panel></td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 109px; height: 35px;">
                                                            <dx:ASPxLabel ID="ASPxLabel4" runat="server" Text="รหัส : ชื่อวัตถุดิบ : ">
                                                            </dx:ASPxLabel>
                                                        </td>
                                                        <td style="height: 35px; width: 245px" width="100%">
                                                            <asp:DropDownList ID="ddlist" runat="server" DataSourceID="sqlItem" 
                                                                DataTextField="FULL_Materail_name" DataValueField="Material_ID">
                                                            </asp:DropDownList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 109px; height: 35px;">
                                                            <dx:ASPxLabel ID="ASPxLabel5" runat="server" Text="จำนวน : ">
                                                            </dx:ASPxLabel>
                                                        </td>
                                                        <td style="height: 35px; width: 245px" width="100%">
                                                            <dx:ASPxTextBox ID="txtTotal" runat="server" Width="170px">
                                                            </dx:ASPxTextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 109px; height: 35px;">
                                                            <dx:ASPxLabel ID="ASPxLabel6" runat="server" Text="พนักงานทำรายการ :">
                                                            </dx:ASPxLabel>
                                                        </td>
                                                        <td style="height: 35px; width: 245px" width="100%">
                                                            <dx:ASPxTextBox ID="txtAct" runat="server" Width="225px">
                                                            </dx:ASPxTextBox>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="width: 109px; height: 35px;">
                                                            &nbsp;</td>
                                                        <td style="height: 35px; width: 245px" width="100%">
                                                            <dx:ASPxButton ID="btSaveAndReport" runat="server" Height="50px" 
                                                                onclick="btSaveAndReport_Click" Text="บันทึก" Width="180px">
                                                            </dx:ASPxButton>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </ContentTemplate>
                                        </asp:UpdatePanel>
                                            </td>
                                    </tr>
                                    <tr>
                                        <td style="height: 18px; width: 351px">
                                            <asp:SqlDataSource ID="sqlItem" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT Material_ID, Materail_name, Material_ID + ' : ' + Materail_name AS FULL_Materail_name FROM TB_Material">
                                            </asp:SqlDataSource>
                                            <asp:SqlDataSource ID="sqlCatego" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT Status_MID, Status_MName FROM TB_StatusBuyMaterial">
                                            </asp:SqlDataSource>
                                            <asp:SqlDataSource ID="sqlStock" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                SelectCommand="SELECT seUnit.Material_ID, seUnit.Materail_name, ISNULL(Inm.Total - OutM.SumTotal, 0) AS TotalSum, seUnit.Unit_Name FROM (SELECT Material_ID, ISNULL(SUM(Material_Count), 0) AS Total FROM TB_Material_StockIN GROUP BY Material_ID) AS Inm FULL OUTER JOIN (SELECT Material_ID, ISNULL(SUM(Material_Count), 0) AS SumTotal FROM TB_Material_StockOUT GROUP BY Material_ID) AS OutM ON Inm.Material_ID = OutM.Material_ID INNER JOIN (SELECT Mat.Material_ID, Mat.Materail_name, Unit.Unit_Name FROM TB_Material AS Mat INNER JOIN TB_Unit_Category AS Unit ON Mat.Unit = Unit.Unit_ID) AS seUnit ON Inm.Material_ID = seUnit.Material_ID">
                                            </asp:SqlDataSource>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <dx:ASPxGridView ID="ASPxGridView2" runat="server" AutoGenerateColumns="False" 
                                                DataSourceID="sqlStM" KeyFieldName="Material_ID" Width="100%" 
                                                OnRowCommand="ASPxGridView2_RowCommand">
                                                <Columns>
                                                    <dx:GridViewDataDateColumn Caption="วันที่และเวลา" FieldName="M_Date" 
                                                        ShowInCustomizationForm="True" VisibleIndex="0">
                                                        <PropertiesDateEdit DisplayFormatString="dd/MM/yyyy HH:mm:ss" 
                                                            EditFormat="DateTime">
                                                        </PropertiesDateEdit>
                                                    </dx:GridViewDataDateColumn>
                                                    <dx:GridViewDataTextColumn Caption="รหัสวัตถุดิบ" FieldName="Material_ID" 
                                                        ReadOnly="True" ShowInCustomizationForm="True" VisibleIndex="1">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn Caption="ชื่อวัตถุดิบ" FieldName="Materail_name" 
                                                        ShowInCustomizationForm="True" VisibleIndex="2">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn Caption="จำนวน" FieldName="Material_Count" 
                                                        ShowInCustomizationForm="True" VisibleIndex="3">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn Caption="ผู้ทำรายการ" FieldName="Act_Officer" 
                                                        ShowInCustomizationForm="True" VisibleIndex="5">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn Caption="หน่วย" FieldName="Unit_Name" 
                                                        ShowInCustomizationForm="True" VisibleIndex="4">
                                                    </dx:GridViewDataTextColumn>
                                                    <dx:GridViewDataTextColumn Caption="ลบ" ShowInCustomizationForm="True" 
                                                        VisibleIndex="7">
                                                        <DataItemTemplate>
                                                            <dx:ASPxButton ID="btnImageAndText" runat="server" BackColor="White" 
                                                                CommandArgument='<%#Eval("M_Date")%>' CommandName="Cmd_Delete" 
                                                                Text="ลบรายการ" Width="120px">
                                                                <ClientSideEvents Click="function(s,e) { e.processOnServer = confirm('Are you sure?'); }" />
                                                            </dx:ASPxButton>
                                                        </DataItemTemplate>
                                                    </dx:GridViewDataTextColumn>
                                                </Columns>
                                                <Settings ShowFilterRow="True" />
                                            </dx:ASPxGridView>
                                            <asp:SqlDataSource ID="sqlStM" runat="server" 
                                                ConnectionString="<%$ ConnectionStrings:DB_Udrink %>" 
                                                
                                                SelectCommand="SELECT INM.M_Date, M.Material_ID, M.Materail_name, INM.Material_Count, INM.Act_Officer, UC.Unit_Name FROM TB_Material_StockOUT AS INM INNER JOIN TB_Material AS M ON INM.Material_ID = M.Material_ID INNER JOIN TB_Unit_Category AS UC ON M.Unit = UC.Unit_ID ORDER BY INM.M_Date DESC">
                                            </asp:SqlDataSource>
                                        </td>
                                        </tr>
                                </table>
                                </fieldset>
                            </asp:Panel>
                        </td>
                    </tr>
                </table>
            </dx:PanelContent>
        </PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>
